
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>addAccount</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
    <script>
        $(function(){
            $("#name").blur(function () {
                // alert("失去了焦点");
                var name=$(this).val();
                <%--$.get(--%>
                <%--    "${pageContext.request.contextPath}/account/checkName",--%>
                <%--    {name:name},--%>
                <%--    function (data) {--%>
                <%--        var span = $("#s_name");--%>
                <%--        if(data.userExist){--%>
                <%--            span.css("color","red");--%>
                <%--            span.html(data.msg);--%>
                <%--        }else {--%>
                <%--            span.css("color","green");--%>
                <%--            span.html(data.msg);--%>
                <%--        }--%>
                <%--    }),"json";--%>
                $.ajax({
                    url: "account/checkName?t="+new Date().getTime(),
                    contentType: "application/json;charset=UTF-8",
                    data: {name:name},
                    dataType: "json",
                    type: "get",
                    success: function (data) {
                                var span = $("#s_name");
                                if(data.userExist){
                                    span.css("color","red");
                                    span.html(data.msg);
                                }else {
                                    span.css("color","green");
                                    span.html(data.msg);
                                }
                }
            });
        });});
    </script>
</head>
<body>
<center><h2>保存账户</h2></center>
<table align="center" width="600">
<form action="account/save" method="post">
   <tr>
       <td>姓名：</td>
       <td><input type="text" id="name" name="name"><span id="s_name"></span></td>
   </tr>
    <tr>
        <td>金额：</td>
        <td><input type="text" name="money"></td>
    </tr>
    <tr>
        <td align="center">
        <input type="submit" value="保存">
        </td>
    </tr>
</form>
</table>
</body>
</html>
